package com.ys.peony.ui.widget;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ys.peony.R;

/**
 * Created by huang on 2016/8/25.
 */
public class PermissionDialog extends AlertDialog {
    private Activity context;
    private static final int REQUEST_PERMISSION_SETTING=0x002;
    public PermissionDialog(Activity context, int themeResId) {
        super(context, themeResId);
        this.context=context;
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_dialog);
        TextView contactTv=(TextView)findViewById(R.id.common_title_tv);
        contactTv.setText("进入授权设置");
        Button cancleBtn=(Button)findViewById(R.id.common_cancle_btn);
        cancleBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        Button comfirmBtn=(Button)findViewById(R.id.common_confirm_btn);
        comfirmBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                Uri uri = Uri.fromParts("package", context.getPackageName(), null);
                intent.setData(uri);
                context.startActivityForResult(intent,REQUEST_PERMISSION_SETTING);
                dismiss();
            }
        });
    }
}
